package com.lapelife.backend.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class CorsConfigure implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        // 运行跨域的路径
        registry.addMapping("/**")
                // 运行跨域请求的域名
                .allowedOriginPatterns("*")
                // .allowedOrigins("http://localhost:8080")
                // 放行请求方法
                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
                // 运行请求头
                .allowedHeaders("*")
                // 允许cookie
                .allowCredentials(true)
                // 超时时间
                .maxAge(3600);
    }
}
